<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Orders_tiku extends User_Controller {

	public function __construct()
    {
        parent::__construct();
        // Your own constructor code
        $this->smarty->assign("current_class", $this->router->fetch_class());
        $this->smarty->assign("current_method",$this->router->fetch_method());
		$this->uid = $this->user_data['id'];
		if( $this->logged_in==0) {header("Location:/");exit;}
    }

    /**
	 * 题库订单列表
	 */
	public function index($status = -1, $order_num = 0, $begin_time = 0, $end_time = 0,  $limit = 0)
	{
        $post_data = $this->input->post();
		if($post_data){
			$status = !empty($post_data['status']) ? $post_data['status'] : -1;
			$order_num = !empty($post_data['order_num']) ? $post_data['order_num'] : 0;
			$begin_time = !empty($post_data['begin_time']) ? $post_data['begin_time'] : 0;
			$end_time = !empty($post_data['end_time']) ? $post_data['end_time'] : 0;
		}
        $data = array(
            'status' => $status,
            'order_type' => 4,
            'begin_time' => $begin_time,
            'end_time' => $end_time,
            'order_num' => $order_num,
            'search_type' => 1,
        );
        $this->load->model('User_center_model');
        if($limit > 0 && is_ajax_request()) $limit = ($limit - 1) * $this->offset;
		$result = $this->User_center_model->get_order_list_by_uid($limit,$this->offset,$this->user_data['id'],$data);
		$this->smarty->assign("data", $data);
		if(is_ajax_request()){
			if(!empty($result['result'])){
				foreach ($result['result'] as $key => $value) {
					$result['result'][$key]['order_time'] = date("Y-m-m H:i:s", $value['order_time']);
				}
				echo json_encode($result['result']);
			}else{
				echo json_encode(array());
			}
			exit;
		}
		$this->smarty->assign("order", $result['result']);
		//分页
		$this->load->library('pagination');
		$page_config['base_url'] = '/user/orders_tiku/index/'.$status.'/'.$order_num.'/'.$begin_time.'/'.$end_time;
		$page_config['total_rows'] = $result['total_count'];
		$page_config['per_page'] = $this->offset;
		$page_config['uri_segment'] = 8;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();

		$this->smarty->assign("pagination", $pagination);
		$this->smarty->assign("count", ceil($result['total_count'] / $this->offset)+1);
		
		$this->smarty->assign("menu", "orders");
		$this->smarty->display("user/order_tiku.html");
	}


}